package cn.bouncyslime.dataStructures.linearList.linkedList;

import cn.bouncyslime.dataStructures.linearList.linkedList.entity.Node;

/**
 * 线性表的链式表示，删除指定位置的结点
 * 作者：张一卓
 * 创建日期：2020/9/26
 */
public class ListDelete {
    public static <T> void delete(Node<T> root, int index){
        Node<T> precursor = root;
        // 0 1 2 3 4
        for (int i = 0; i < index; i++){
            precursor = precursor.getNext();
        }
        precursor.setNext(precursor.getNext().getNext());
    }

    public static void main(String[] args) {
        Node<Integer> root = LinkedListInit.integerInit();
        LinkedListUtils.printLinkedList(root);
        delete(root, 0);
        LinkedListUtils.printLinkedList(root);
    }
}
